package jmars.mobile.datainvetigation;

import java.text.DecimalFormat;

public class NumericalFeature {
	private Double min;
	private Double max;
	private Double sum;
	private Integer count;
	private Double avg;
	private Double med;
	private Double uQuart;
	private Double lQuart;
	private Double medPre;
	private Double medNext;
	private Double uQuartPre;
	private Double uQuartNext;
	private Double lQuartPre;
	private Double lQuartNext;
	DecimalFormat df = new DecimalFormat();
	
	public NumericalFeature(){
		setAvg(0D);
		setCount(0);
		setSum(0D);
		df.applyPattern("0,000.000");
	}
	
	@Override
	public String toString(){
		return "count:"+count+", sum:"+df.format(sum)+", min:"+min+", max:"+max+", avg:"+df.format(avg)+", med:"+med+", lQuart:"+lQuart+", uQuart"+uQuart;
	}
	
	public void update(Double item){
		this.setCount(this.getCount()+1);
		this.setSum(this.getSum()+item);
		if(null==this.getMin()||this.getMin()>item)this.setMin(item);
		if(null==this.getMax()||this.getMax()<item)this.setMax(item);
		this.setAvg(this.getSum()/this.getCount());
		if(this.getMin()>item)this.setMin(item);
		
		if(null==this.getMed())this.setMed(item);
		else if(this.getMed()<item){
			if(this.getCount()%2==0)
				if(null==this.getMedNext()||this.getMedNext()>item)this.setMedNext(item);
			else{
				if(this.getMedNext()>item){
					this.setMedPre(this.getMed());
					this.setMed(item);
				}else{
					this.setMed(this.getMedNext());
				}
			}
		}else if(this.getMed()>=item){
			if(this.getCount()%2==0){
				if(null==this.getMedNext()){
					this.setMedNext(this.getMed());
				}
				if(null==this.getMedPre()||this.getMedPre()<item)this.setMed(item);
				else{
					this.setMed(this.getMedPre());
					this.setMedPre(item);
				}
			}else{
				if(null==this.getMedPre()||this.getMedPre()<item)this.setMedPre(item);
			}
		}
	}
	
	public Double getMin() {
		return min;
	}
	public void setMin(Double min) {
		this.min = min;
	}
	public Double getMax() {
		return max;
	}
	public void setMax(Double max) {
		this.max = max;
	}
	public Double getSum() {
		return sum;
	}
	public void setSum(Double sum) {
		this.sum = sum;
	}
	public Integer getCount() {
		return count;
	}
	public void setCount(Integer count) {
		this.count = count;
	}
	public Double getAvg() {
		return avg;
	}
	public void setAvg(Double avg) {
		this.avg = avg;
	}
	public Double getMed() {
		return med;
	}
	public void setMed(Double med) {
		this.med = med;
	}
	public Double getuQuart() {
		return uQuart;
	}
	public void setuQuart(Double uQuart) {
		this.uQuart = uQuart;
	}
	public Double getlQuart() {
		return lQuart;
	}
	public void setlQuart(Double lQuart) {
		this.lQuart = lQuart;
	}
	public Double getMedPre() {
		return medPre;
	}
	public void setMedPre(Double medPre) {
		this.medPre = medPre;
	}
	public Double getMedNext() {
		return medNext;
	}
	public void setMedNext(Double medNext) {
		this.medNext = medNext;
	}
	public Double getuQuartPre() {
		return uQuartPre;
	}
	public void setuQuartPre(Double uQuartPre) {
		this.uQuartPre = uQuartPre;
	}
	public Double getuQuartNext() {
		return uQuartNext;
	}
	public void setuQuartNext(Double uQuartNext) {
		this.uQuartNext = uQuartNext;
	}
	public Double getlQuartPre() {
		return lQuartPre;
	}
	public void setlQuartPre(Double lQuartPre) {
		this.lQuartPre = lQuartPre;
	}
	public Double getlQuartNext() {
		return lQuartNext;
	}
	public void setlQuartNext(Double lQuartNext) {
		this.lQuartNext = lQuartNext;
	}
	
	
}
